home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / ov-struct.h < prev    next >
C/C++ Source or Header  |  1996-11-07  |  3KB  |  119 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_struct_h)
  24. #define octave_struct_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. #include <cstdlib>
  31.  
  32. #include <string>
  33.  
  34. class ostream;
  35.  
  36. #include "mx-base.h"
  37. #include "str-vec.h"
  38.  
  39. #include "error.h"
  40. #include "oct-alloc.h"
  41. #include "oct-map.h"
  42. #include "ov-base.h"
  43. #include "ov-typeinfo.h"
  44.  
  45. class Octave_map;
  46. class octave_value_list;
  47.  
  48. class tree_walker;
  49.  
  50. // Data structures.
  51.  
  52. class
  53. octave_struct : public octave_base_value
  54. {
  55. public:
  56.  
  57.   octave_struct (void)
  58.     : octave_base_value () { }
  59.  
  60.   octave_struct (const Octave_map& m)
  61.     : octave_base_value (), map (m) { }
  62.  
  63.   octave_struct (const octave_struct& s)
  64.     : octave_base_value (), map (s.map) { }
  65.  
  66.   ~octave_struct (void) { }
  67.  
  68.   octave_value *clone (void) { return new octave_struct (*this); }
  69.  
  70.   void *operator new (size_t size)
  71.     { return allocator.alloc (size); }
  72.  
  73.   void operator delete (void *p, size_t size)
  74.     { allocator.free (p, size); }
  75.  
  76.   octave_value struct_elt_val (const string& nm, bool silent) const;
  77.  
  78.   octave_value& struct_elt_ref (const string& nm);
  79.  
  80.   bool is_defined (void) const { return true; }
  81.  
  82.   bool is_map (void) const { return true; }
  83.  
  84.   Octave_map map_value (void) const { return map; }
  85.  
  86.   void print (ostream& os, bool pr_as_read_syntax = false);
  87.  
  88.   int type_id (void) const { return t_id; }
  89.  
  90.   string type_name (void) const { return t_name; }
  91.  
  92.   static int static_type_id (void) { return t_id; }
  93.  
  94.   static void register_type (void)
  95.     { t_id = octave_value_typeinfo::register_type (t_name); }
  96.  
  97. private:
  98.  
  99.   // The associative array used to manage the structure data.
  100.   Octave_map map;
  101.  
  102.   // For custom memory management.
  103.   static octave_allocator allocator;
  104.  
  105.   // Type id of struct objects, set by register_type().
  106.   static int t_id;
  107.  
  108.   // Type name of struct objects, defined in ov-struct.cc.
  109.   static const string t_name;
  110. };
  111.  
  112. #endif
  113.  
  114. /*
  115. ;;; Local Variables: ***
  116. ;;; mode: C++ ***
  117. ;;; End: ***
  118. */
  119.